<template>
    <li class="Purchase">
        <el-form ref="form" :model="form" label-width="68px">
            <el-form-item :label="$t('jiaoyi[0]')">
                <el-input :placeholder="$t('jiaoyi[1]')" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item :label="$t('jiaoyi[2]')">
                <el-input v-model="form.total_price"></el-input>
                <el-radio-group v-model="radio1" @change="buynumchange">
                    <el-radio-button label="0.25">25%</el-radio-button>
                    <el-radio-button label="0.5">50%</el-radio-button>
                    <el-radio-button label="0.75">75%</el-radio-button>
                    <el-radio-button label="1">100%</el-radio-button>
                </el-radio-group>
            </el-form-item>
        </el-form>
        <div class="Purchasefooter">
            <p>
                <!-- {{$t('other[2]')}}<span>{{zongjia}}</span> -->
            </p>
            <p>{{$t('jiaoyi[6]')}}<span>{{canUseMoney}}</span></p>
        </div>
        <el-button type="success" @click="preservation">{{$t('order[4]')}}</el-button>
        <!-- <el-button type="success" v-if="Prodata.buy_up == 0" >{{$t('order[4]')}}</el-button> -->
    </li>
</template>

<script>

import { CalculationTotal, CalculationPrice } from "@/libs/util";
export default {
    name: 'marketpricesell',
    props:['Prodata', "codetype","canUseMoney"],
    data () {
        return {
            form:{
                "code": "",//币种标识
                "total_num": "0",//委托总数量 （市价卖出必填）
                "total_price": "",//委托总金额 （市价买入必填）
                "type": "1",//1买入 2卖出 （必填）
                "otype": "2",//1限价 2市价 （必填）
            },
            radio1: 0,
            code:"",
            zongjia:"0",
        }
    },
    watch: {
        'Prodata.code': function(newVal, oldVal){
            if(newVal){
                this.code = _.toUpper(_.split(newVal, "/")[0]);
                this.form.code = newVal;
            };
        },
        'form.total_price': function(newVal, oldVal){
            if(newVal){
                this.zongjia = _.round(_.toFinite(newVal), 4);
            }else{
                this.zongjia = 0;
            }
        },
    },
    methods: {
        buynumchange(data){
            let balance = this.$store.state.user.assetList.USDT.balance;
            this.form.total_price = _.round(_.multiply(_.toFinite(balance), this.radio1), 4);
            this.zongjia = _.round(_.multiply(_.toFinite(balance), this.radio1), 4);
        },
        preservation(){
            let Prodata = _.cloneDeep(this.form);
            if(!Prodata.total_price){
                this.$message.error(this.$t('header.tishi[7]'));
                return false;
            };
            this.$emit('func', this.form)
        }
    },
    created(){

    },
    components: {
        
    },
}
</script>

